//
//  XLHTTPSessionManager.m
//  XiangLove
//
//  Created by 陈宪栋 on 2017/11/28.
//  Copyright © 2017年 BAOMIHUA.COM. All rights reserved.
//

#import "XLHTTPSessionManager.h"
#import <AFNetworkActivityIndicatorManager.h>
#import <NSString+NSHash.h>
#import <UIViewController+TopViewController.h>
#import "XLV2LoginViewController.h"
#import "XLHTTPSessionManager+Analytics.h"
#import "BMHWithdrawalListModel.h"
#import "BMHGifyearMonthModel.h"
#import "XLCharmModel.h"
#import "XLLevelInforModel.h"
#import "NSString+Ext.h"

static NSString *XLHTTPCacheName = @"XLCache";
static NSString *XLAPIManagerErrorDomain = @"WAPIManagerErrorDomain";
static NSInteger XLAPIManagerNoNetworkException = 6666;//手机本地无网络
static NSInteger XLAPIManagerResponseSuccess = 1;//请求返回成功
static NSInteger XLAPIManagerResponseSuccessOld = 0;//请求返回成功
static dispatch_once_t onceToken;



@interface XLHTTPSessionManager ()
@property (nonatomic, strong) NSDictionary *headerParameters;
@property (nonatomic, strong) YYCache *cache;

@end

@implementation XLHTTPSessionManager
+(void)attemptDealloc{
    onceToken = 0; // 只有置成0,GCD才会认为它从未执行过.它默认为0.这样才能保证下次再次调用shareInstance的时候,再次创建对象.
}

+ (instancetype)sharedManager {
    static XLHTTPSessionManager *instance;
    dispatch_once(&onceToken, ^{
        NSString *xlapi = BaseURL;
        if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"isTestUrl"]isEqualToString:@"yes"]) {
            xlapi = @"http://test.xinliao.xiuquapp.com";
        }
        instance = [[self alloc] initWithBaseURL:[NSURL URLWithString:xlapi]];
        instance.cache = [[YYCache alloc] initWithName:XLHTTPCacheName];
        instance.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",@"text/plain", @"text/json",nil];
        [instance.requestSerializer setValue:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] forHTTPHeaderField:@"version"];
        [instance.requestSerializer setValue:QudaoName forHTTPHeaderField:@"qudao"];
        [instance.requestSerializer setValue:[NSString iPhoneName] forHTTPHeaderField:@"phoneType"];
        [instance.requestSerializer setValue:[[UIDevice currentDevice] systemVersion] ?:@"" forHTTPHeaderField:@"osVersion"];
        [instance.requestSerializer setValue:[UserDefaults objectForKey:UserID] forHTTPHeaderField:@"userId"];
        [instance.requestSerializer setValue:[UserDefaults objectForKey:UserToken] forHTTPHeaderField:@"token"];
        [instance.requestSerializer setValue:@"1" forHTTPHeaderField:@"appId"];
        [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];

        AFNetworkReachabilityManager *afNetworkReachabilityManager = [AFNetworkReachabilityManager sharedManager];
        [afNetworkReachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
            switch (status) {
                    case AFNetworkReachabilityStatusNotReachable:{
                        BMHLog(@"无网络");
                        break;
                    }
                    case AFNetworkReachabilityStatusReachableViaWiFi:{
                        BMHLog(@"WiFi网络");
                        break;
                    }
                    case AFNetworkReachabilityStatusReachableViaWWAN:{
                        BMHLog(@"无线网络");
                        break;
                    }
                default:
                    break;
            }
        }];
        [afNetworkReachabilityManager startMonitoring];
    });
    return instance;
}
+ (instancetype)sharedBMHManager {
    static dispatch_once_t onceToken;
    static XLHTTPSessionManager *instance;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] initWithBaseURL:[NSURL URLWithString:@"http://app.interface.baomihua.com"]];
        instance.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",@"text/plain", @"text/json",nil];
    });
    return instance;
}


#pragma mark - #老版本V1
- (RACSignal *)POST:(NSString *)URLString parameters:(NSDictionary *)parameters resultClass:(Class)resultClass {
    @weakify(self);
    RACSignal *requestSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        @strongify(self);
        NSURLSessionDataTask *task = [self POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    return [requestSignal flattenMap:^RACStream *(NSDictionary *data) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            if (data == nil) {
                NSString *msg = @"空数据";
                NSInteger code = 803;
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
                return nil;
            }
            NSError *err;
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data
                                                               options:0
                                                                 error:&err];
            NSString *jsonString = [[NSString alloc] initWithData:jsonData
                                                         encoding:NSUTF8StringEncoding];
            BMHLog(@"%@", jsonString);
            NSInteger state = [[data objectForKey:@"success"] integerValue];
            id resultObj = [data objectForKey:@"data"];
            if (state == XLAPIManagerResponseSuccessOld) {
                if ([resultObj isKindOfClass:[NSArray class]]) {
                    NSArray *resultArray = resultObj;
                    if (resultClass) {
                        resultObj = [[NSMutableArray alloc] init];
                        for (NSDictionary *dic in resultArray) {
                            id obj = [resultClass modelWithDictionary:dic];
                            [resultObj addObject:obj];
                        }
                    }
                }
                else if ([resultObj isKindOfClass:[NSDictionary class]]) {
                    if (resultClass) {
                        id obj = [resultClass modelWithDictionary:resultObj];
                        resultObj = obj;
                    }
                }
                if (data) {
                    [self.cache setObject:data forKey:F(@"%@%@", URLString, parameters)];
                }
                [subscriber sendNext:resultObj];
                [subscriber sendCompleted];
            } else {
                NSString *msg = [data objectForKey:@"errmsg"];
                NSInteger code = [[data objectForKey:@"errcode"] integerValue];
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
            }
            return nil;
        }];
    }];
}


- (RACSignal *)XLPOST:(NSString *)URLString parameters:(NSDictionary *)parameters resultClass:(Class)resultClass {
//    switch (self.cachePloy) {
//        case XLHTTPCachePloy_Cache: {
//            id cacheData = [self.cache objectForKey:F(@"%@%@",URLString, parameters)];
//            return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//                [subscriber sendNext:cacheData];
//                [subscriber sendCompleted];
//                return nil;
//            }];
//        }
//            break;
//        case XLHTTPCachePloy_Normal: {
//            id cacheData = [self.cache objectForKey:F(@"%@%@",URLString, parameters)];
//            if (cacheData) {
//                return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//                    [subscriber sendNext:cacheData];
//                    [subscriber sendCompleted];
//                    return nil;
//                }];
//            }
//        }
//            break;
//
//        default:
//            break;
//    }
    
    @weakify(self);
    RACSignal *requestSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        @strongify(self);
        NSURLSessionDataTask *task = [self POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    return [requestSignal flattenMap:^RACStream *(NSDictionary *data) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            if (data == nil) {
                NSString *msg = @"空数据";
                NSInteger code = 803;
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
                return nil;
            }
            NSError *err;
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data
                                                               options:0
                                                                 error:&err];
            NSString *jsonString = [[NSString alloc] initWithData:jsonData
                                                         encoding:NSUTF8StringEncoding];
            BMHLog(@"%@", jsonString);
            NSInteger state = [[data objectForKey:@"success"] integerValue];
            id resultObj = [data objectForKey:@"data"];
            if (state == XLAPIManagerResponseSuccessOld) {
                if ([resultObj isKindOfClass:[NSArray class]]) {
                    NSArray *resultArray = resultObj;
                    if (resultClass) {
                        resultObj = [[NSMutableArray alloc] init];
                        for (NSDictionary *dic in resultArray) {
                            id obj = [resultClass modelWithDictionary:dic];
                            [resultObj addObject:obj];
                        }
                    }
                }
                else if ([resultObj isKindOfClass:[NSDictionary class]]) {
                    if (resultClass) {
                        id obj = [resultClass modelWithDictionary:resultObj];
                        resultObj = obj;
                    }
                }
                if (resultObj) {
                    [self.cache setObject:resultObj forKey:F(@"%@%@", URLString, parameters)];
                }
                [subscriber sendNext:resultObj];
                [subscriber sendCompleted];
            } else {
                NSString *msg = [data objectForKey:@"errmsg"];
                NSInteger code = [[data objectForKey:@"errcode"] integerValue];
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
            }
            return nil;
        }];
    }];
}



- (RACSignal *)GET:(NSString *)URLString parameters:(NSDictionary *)parameters resultClass:(Class)resultClass {
   
    @weakify(self);
    RACSignal *requestSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        @strongify(self);
        NSURLSessionDataTask *task = [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    return [requestSignal flattenMap:^RACStream *(NSDictionary *data) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            if (data == nil) {
                NSString *msg = @"空数据";
                NSInteger code = 803;
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
                return nil;
            }
            NSError *err;
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data
                                                               options:0
                                                                 error:&err];
            NSString *jsonString = [[NSString alloc] initWithData:jsonData
                                                         encoding:NSUTF8StringEncoding];
            BMHLog(@"data = %@", jsonString);
            NSInteger state = [[data objectForKey:@"success"] integerValue];
            id resultObj = [data objectForKey:@"data"];
            if (state == XLAPIManagerResponseSuccessOld) {
                if ([resultObj isKindOfClass:[NSArray class]]) {
                    NSArray *resultArray = resultObj;
                    if (resultClass) {
                        resultObj = [[NSMutableArray alloc] init];
                        for (NSDictionary *dic in resultArray) {
                            id obj = [resultClass modelWithDictionary:dic];
                            [resultObj addObject:obj];
                        }
                    }
                }
                else if ([resultObj isKindOfClass:[NSDictionary class]]) {
                    if (resultClass) {
                        id obj = [resultClass modelWithDictionary:resultObj];
                        resultObj = obj;
                    }
                }
                if (resultObj) {
                    [self.cache setObject:resultObj forKey:F(@"%@%@", URLString, parameters)];
                }
                [subscriber sendNext:resultObj];
                [subscriber sendCompleted];
            } else {
                NSString *msg = [data objectForKey:@"errmsg"];
                NSInteger code = [[data objectForKey:@"success"] integerValue];
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
            }
            return nil;
        }];
    }];
}
#pragma mark - #新版V2
- (RACSignal *)XLV2GET:(NSString *)URLString parameters:(NSDictionary *)parameters resultClass:(Class)resultClass {

    
//    switch (self.cachePloy) {
//        case XLHTTPCachePloy_Cache: {
//            id cacheData = [self.cache objectForKey:F(@"%@%@",URLString, parameters)];
//            return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//                [subscriber sendNext:cacheData];
//                [subscriber sendCompleted];
//                return nil;
//            }];
//        }
//            break;
//        case XLHTTPCachePloy_Normal: {
//            id cacheData = [self.cache objectForKey:F(@"%@%@",URLString, parameters)];
//            if (cacheData) {
//                return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//                    [subscriber sendNext:cacheData];
//                    [subscriber sendCompleted];
//                    return nil;
//                }];
//            }
//        }
//            break;
//
//        default:
//            break;
//    }
    
    @weakify(self);
    RACSignal *requestSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        @strongify(self);
        NSURLSessionDataTask *task = [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    return [requestSignal flattenMap:^RACStream *(NSDictionary *data) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            if (data == nil) {
                NSString *msg = @"空数据";
                NSInteger code = 803;
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
                return nil;
            }
            NSError *err;
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data
                                                               options:0
                                                                 error:&err];
            NSString *jsonString = [[NSString alloc] initWithData:jsonData
                                                         encoding:NSUTF8StringEncoding];
            BMHLog(@"data = %@", jsonString);
            NSInteger state = [[data objectForKey:@"ApiIntCode"] integerValue];
            id resultObj = [data objectForKey:@"ApiData"];
            if ([[data objectForKey:@"code"] integerValue] == 200) {
                state = XLAPIManagerResponseSuccess;
                resultObj = [data objectForKey:@"data"];
            }
            if (state == XLAPIManagerResponseSuccess) {
                if ([resultObj isKindOfClass:[NSArray class]]) {
                    NSArray *resultArray = resultObj;
                    if (resultClass) {
                        resultObj = [[NSMutableArray alloc] init];
                        for (NSDictionary *dic in resultArray) {
                            id obj = [resultClass modelWithDictionary:dic];
                            [resultObj addObject:obj];
                        }
                    }
                }
                else if ([resultObj isKindOfClass:[NSDictionary class]]) {
                    if (resultClass) {
                        id obj = [resultClass modelWithDictionary:resultObj];
                        resultObj = obj;
                    }
                }
                if (resultObj) {
                    [self.cache setObject:resultObj forKey:F(@"%@%@", URLString, parameters)];
                }
                [subscriber sendNext:resultObj];
                [subscriber sendCompleted];
            } else {
                NSString *msg = [data objectForKey:@"ApiMessage"];
                NSInteger code = [[data objectForKey:@"ApiIntCode"] integerValue];
                if (code == 0) {
                    [MBProgressHUD showContent:@"请重试!"];
                    return nil;
                }
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
                UIViewController *topmostVC = [self topViewController];
                if (code == 4 && ![topmostVC isKindOfClass:[XLV2LoginViewController class]]) {
                    XLV2LoginViewController *vc = [[XLV2LoginViewController alloc] init];
                    vc.navigationItem.title = @"切换账号";
                    [MBProgressHUD showContent:@"用户信息失效"];
                    [[XLAccountManager shareInstance] removeUserInfo];
                    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
                    [[UIViewController topViewController] presentViewController:nav animated:YES completion:nil];
                }
            }
            return nil;
        }];
    }];
}
- (UIViewController *)topViewController {
    UIViewController *resultVC;
    resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
    while (resultVC.presentedViewController) {
        resultVC = [self _topViewController:resultVC.presentedViewController];
    }
    return resultVC;
}

- (UIViewController *)_topViewController:(UIViewController *)vc {
    if ([vc isKindOfClass:[UINavigationController class]]) {
        return [self _topViewController:[(UINavigationController *)vc topViewController]];
    } else if ([vc isKindOfClass:[UITabBarController class]]) {
        return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
    } else {
        return vc;
    }
    return nil;
}
- (RACSignal *)XLV2POST:(NSString *)URLString parameters:(NSDictionary *)parameters resultClass:(Class)resultClass {

//    switch (self.cachePloy) {
//        case XLHTTPCachePloy_Cache: {
//            id cacheData = [self.cache objectForKey:F(@"%@%@",URLString, parameters)];
//            return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//                [subscriber sendNext:cacheData];
//                [subscriber sendCompleted];
//                return nil;
//            }];
//        }
//            break;
//        case XLHTTPCachePloy_Normal: {
//            id cacheData = [self.cache objectForKey:F(@"%@%@",URLString, parameters)];
//            if (cacheData) {
//                return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//                    [subscriber sendNext:cacheData];
//                    [subscriber sendCompleted];
//                    return nil;
//                }];
//            }
//        }
//            break;
//
//        default:
//            break;
//    }
    
    @weakify(self);
    RACSignal *requestSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        @strongify(self);
        NSURLSessionDataTask *task = [self POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    return [requestSignal flattenMap:^RACStream *(NSDictionary *data) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            if (data == nil) {
                NSString *msg = @"空数据";
                NSInteger code = 803;
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
                return nil;
            }
            NSError *err;
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data
                                                               options:0
                                                                 error:&err];
            NSString *jsonString = [[NSString alloc] initWithData:jsonData
                                                         encoding:NSUTF8StringEncoding];
            BMHLog(@"%@", jsonString);
            NSInteger state = [[data objectForKey:@"ApiIntCode"] integerValue];
            id resultObj = [data objectForKey:@"ApiData"];
            if (state == XLAPIManagerResponseSuccess) {
                if ([resultObj isKindOfClass:[NSArray class]]) {
                    NSArray *resultArray = resultObj;
                    if (resultClass) {
                        resultObj = [[NSMutableArray alloc] init];
                        for (NSDictionary *dic in resultArray) {
                            id obj = [resultClass modelWithDictionary:dic];
                            [resultObj addObject:obj];
                        }
                    }
                }
                else if ([resultObj isKindOfClass:[NSDictionary class]]) {
                    if (resultClass) {
                        id obj = [resultClass modelWithDictionary:resultObj];
                        resultObj = obj;
                    }
                }
                if (data) {
                    [self.cache setObject:data forKey:F(@"%@%@", URLString, parameters)];
                }
                [subscriber sendNext:resultObj];
                [subscriber sendCompleted];
            } else {
                NSString *msg = [data objectForKey:@"ApiMessage"];
                NSInteger code = [[data objectForKey:@"ApiIntCode"] integerValue];
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
            }
            return nil;
        }];
    }];
}
#pragma mark - #获取验证码接口
- (RACSignal *)CODEGET:(NSString *)URLString parameters:(NSDictionary *)parameters resultClass:(Class)resultClass {

    switch (self.cachePloy) {
        case XLHTTPCachePloy_Cache: {
            id cacheData = [self.cache objectForKey:F(@"%@%@",URLString, parameters)];
            return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
                [subscriber sendNext:cacheData];
                [subscriber sendCompleted];
                return nil;
            }];
        }
            break;
        case XLHTTPCachePloy_Normal: {
            id cacheData = [self.cache objectForKey:F(@"%@%@",URLString, parameters)];
            if (cacheData) {
                return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
                    [subscriber sendNext:cacheData];
                    [subscriber sendCompleted];
                    return nil;
                }];
            }
        }
            break;
            
        default:
            break;
    }
    
    @weakify(self);
    RACSignal *requestSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        @strongify(self);
        NSURLSessionDataTask *task = [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    return [requestSignal flattenMap:^RACStream *(NSDictionary *data) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            if (data == nil) {
                NSString *msg = @"空数据";
                NSInteger code = 803;
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
                return nil;
            }
            NSError *err;
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data
                                                               options:0
                                                                 error:&err];
            NSString *jsonString = [[NSString alloc] initWithData:jsonData
                                                         encoding:NSUTF8StringEncoding];
            BMHLog(@"%@", jsonString);
            NSInteger state = [[data objectForKey:@"state"] integerValue];
            id resultObj = [data objectForKey:@"data"];
            if (state == 1) {
                if ([resultObj isKindOfClass:[NSArray class]]) {
                    NSArray *resultArray = resultObj;
                    if (resultClass) {
                        resultObj = [[NSMutableArray alloc] init];
                        for (NSDictionary *dic in resultArray) {
                            id obj = [resultClass modelWithDictionary:dic];
                            [resultObj addObject:obj];
                        }
                    }
                }
                else if ([resultObj isKindOfClass:[NSDictionary class]]) {
                    if (resultClass) {
                        id obj = [resultClass modelWithDictionary:resultObj];
                        resultObj = obj;
                    }
                }
                if (resultObj) {
                    [self.cache setObject:resultObj forKey:F(@"%@%@", URLString, parameters)];
                }
                [subscriber sendNext:resultObj];
                [subscriber sendCompleted];
            } else {
                NSString *msg = [data objectForKey:@"info"];
                NSInteger code = [[data objectForKey:@"state"] integerValue];
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
            }
            return nil;
        }];
    }];
}


#pragma mark - #lemon接口请求lemonsdk
/*
- (RACSignal *)LMGET:(NSString *)URLString parameters:(NSDictionary *)parameters resultClass:(Class)resultClass {
    @weakify(self);
    RACSignal *requestSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        @strongify(self);
        NSError *serializationError = nil;
        NSURLRequest *request = [self.requestSerializer requestWithMethod:@"GET" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError];
        if (serializationError) {
            [subscriber sendError:serializationError];
        } else {
            LCBaseEventHandler* handler = [[LCBaseEventHandler alloc] init];
            handler.resumeTime = [[NSDate date] timeIntervalSince1970];
            __weak typeof(handler) weakHandler = handler;
            handler.onResponse = ^LCLemonBasePackage * _Nullable(LCLemonBasePackage * _Nullable package) {
                __strong typeof(weakHandler) strongHandler = weakHandler;
                strongHandler.completeTime = [[NSDate date] timeIntervalSince1970];
                NSTimeInterval responseTime = strongHandler.completeTime - strongHandler.resumeTime;
                NSString *url = request.URL.absoluteString;
                NSString *body = [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding];
                NSLog(@"Lemon\nHTTPURL:\n%@\n\nHTTPBody:\n%@\n\nResponseTime:\n%fms\n", url, body, responseTime * 1000);
                if (package == nil) {
                    NSError *error = [[NSError alloc] initWithDomain:@"lemonError" code:1 userInfo:@{NSLocalizedDescriptionKey:@"package is nil"}];
                    [subscriber sendError:error];
                    return nil;
                }
                if (package.body == nil) {
                    NSError *error = [[NSError alloc] initWithDomain:@"lemonError" code:2 userInfo:@{NSLocalizedDescriptionKey:@"package.body is nil"}];
                    [subscriber sendError:error];
                    return nil;
                }
                
                NSError* error = nil;
                LemonPduTransitHttpMsgResp* resp = [LemonPduTransitHttpMsgResp parseFromData:package.body error:&error];
                if (error != nil) {
                    [subscriber sendError:error];
                }
                NSData *data = [resp.data_p dataUsingEncoding:NSUTF8StringEncoding];
                NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                [subscriber sendNext:dic];
                [subscriber sendCompleted];
                NSLog(@"http get resp: %@", resp);
                return nil;
            };
            [[LCLemonService sharedInstance] send:request.URL.absoluteString data:nil method:HttpMethod_HTTPMethodGet headers:request.allHTTPHeaderFields handler:handler];
        }

        return [RACDisposable disposableWithBlock:^{
        }];
    }];
    return [requestSignal flattenMap:^RACStream *(NSDictionary *data) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            if (data == nil) {
                NSString *msg = @"空数据";
                NSInteger code = 803;
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
                return nil;
            }
            NSError *err;
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data
                                                               options:0
                                                                 error:&err];
            NSString *jsonString = [[NSString alloc] initWithData:jsonData
                                                         encoding:NSUTF8StringEncoding];
            BMHLog(@"%@", jsonString);
            NSInteger state = [[data objectForKey:@"success"] integerValue];
            id resultObj = [data objectForKey:@"data"];
            if (state == XLAPIManagerResponseSuccess) {
                if ([resultObj isKindOfClass:[NSArray class]]) {
                    NSArray *resultArray = resultObj;
                    if (resultClass) {
                        resultObj = [[NSMutableArray alloc] init];
                        for (NSDictionary *dic in resultArray) {
                            id obj = [resultClass modelWithDictionary:dic];
                            [resultObj addObject:obj];
                        }
                    }
                }
                else if ([resultObj isKindOfClass:[NSDictionary class]]) {
                    if (resultClass) {
                        id obj = [resultClass modelWithDictionary:resultObj];
                        resultObj = obj;
                    }
                }
                if (resultObj) {
                    [self.cache setObject:resultObj forKey:F(@"%@%@", URLString, parameters)];
                }
                [subscriber sendNext:resultObj];
                [subscriber sendCompleted];
            } else {
                NSString *msg = [data objectForKey:@"errmsg"];
                NSInteger code = [[data objectForKey:@"errcode"] integerValue];
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
            }
            return nil;
        }];
    }];
}

- (RACSignal *)LMPOST:(NSString *)URLString parameters:(NSDictionary *)parameters resultClass:(Class)resultClass {
    @weakify(self);
    RACSignal *requestSignal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        @strongify(self);
        NSError *serializationError = nil;
        NSURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError];
        if (serializationError) {
            [subscriber sendError:serializationError];
        } else {
            LCBaseEventHandler* handler = [[LCBaseEventHandler alloc] init];
            handler.resumeTime = [[NSDate date] timeIntervalSince1970];
            __weak typeof(handler) weakHandler = handler;
            handler.onResponse = ^LCLemonBasePackage * _Nullable(LCLemonBasePackage * _Nullable package) {
                __strong typeof(weakHandler) strongHandler = weakHandler;
                strongHandler.completeTime = [[NSDate date] timeIntervalSince1970];
                NSTimeInterval responseTime = strongHandler.completeTime - strongHandler.resumeTime;
                NSString *url = request.URL.absoluteString;
                NSString *body = [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding];
                NSLog(@"Lemon\nHTTPURL:\n%@\n\nHTTPBody:\n%@\n\nResponseTime:\n%fms\n", url, body, responseTime * 1000);
                if (package == nil) {
                    NSError *error = [[NSError alloc] initWithDomain:@"lemonError" code:1 userInfo:@{NSLocalizedDescriptionKey:@"package is nil"}];
                    [subscriber sendError:error];
                    return nil;
                }
                if (package.body == nil) {
                    NSError *error = [[NSError alloc] initWithDomain:@"lemonError" code:2 userInfo:@{NSLocalizedDescriptionKey:@"package.body is nil"}];
                    [subscriber sendError:error];
                    return nil;
                }
                
                NSError* error = nil;
                LemonPduTransitHttpMsgResp* resp = [LemonPduTransitHttpMsgResp parseFromData:package.body error:&error];
                if (error != nil) {
                    [subscriber sendError:error];
                }
                NSData *data = [resp.data_p dataUsingEncoding:NSUTF8StringEncoding];
                NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                [subscriber sendNext:dic];
                [subscriber sendCompleted];
                NSLog(@"http get resp: %@", resp);
                return nil;
            };
            NSString *data = [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding];
            [[LCLemonService sharedInstance] send:request.URL.absoluteString data:data method:HttpMethod_HTTPMethodPost headers:request.allHTTPHeaderFields handler:handler];
        }
        
        return [RACDisposable disposableWithBlock:^{
        }];
    }];
    return [requestSignal flattenMap:^RACStream *(NSDictionary *data) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            if (data == nil) {
                NSString *msg = @"空数据";
                NSInteger code = 803;
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
                return nil;
            }
            NSError *err;
            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data
                                                               options:0
                                                                 error:&err];
            NSString *jsonString = [[NSString alloc] initWithData:jsonData
                                                         encoding:NSUTF8StringEncoding];
            BMHLog(@"%@", jsonString);
            NSInteger state = [[data objectForKey:@"success"] integerValue];
            id resultObj = [data objectForKey:@"data"];
            if (state == XLAPIManagerResponseSuccess) {
                if ([resultObj isKindOfClass:[NSArray class]]) {
                    NSArray *resultArray = resultObj;
                    if (resultClass) {
                        resultObj = [[NSMutableArray alloc] init];
                        for (NSDictionary *dic in resultArray) {
                            id obj = [resultClass modelWithDictionary:dic];
                            [resultObj addObject:obj];
                        }
                    }
                }
                else if ([resultObj isKindOfClass:[NSDictionary class]]) {
                    if (resultClass) {
                        id obj = [resultClass modelWithDictionary:resultObj];
                        resultObj = obj;
                    }
                }
                if (resultObj) {
                    [self.cache setObject:resultObj forKey:F(@"%@%@", URLString, parameters)];
                }
                [subscriber sendNext:resultObj];
                [subscriber sendCompleted];
            } else {
                NSString *msg = [data objectForKey:@"errmsg"];
                NSInteger code = [[data objectForKey:@"errcode"] integerValue];
                NSError *error = [[NSError alloc] initWithDomain:XLAPIManagerErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey:msg}];
                [subscriber sendError:error];
            }
            return nil;
        }];
    }];
}
*/
#pragma mark -
+ (void)upLoadImageFileWithImage:(UIImage *)image Progress:(void (^)(id))progress Success:(void (^)(id))success Failure:(void(^)(id))failure {
    NSString *url1 = @"http://wsp001.baomihua.com/InsertImg.ashx/?crystr=";
    NSString *url2 = @"pomoho88888";
    NSString *url3 = @"&userId=88888";
    NSString *urlString = [NSString stringWithFormat:@"%@%@%@",url1,[[url2 md5Encrypt] lowercaseString],url3];
    NSLog(@"上传  %@",urlString);
    //1。创建管理者对象
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    NSData *data = UIImageJPEGRepresentation(image, 1.0);
    // 可以在上传时使用当前的系统时间作为文件名(解决重名)
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // 设置时间格式
    formatter.dateFormat = @"yyyyMMddHHmmss";
    NSString *str = [formatter stringFromDate:[NSDate date]];
    NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
    //2.上传文件
    NSDictionary *dict = @{@"file":data};
    
    [manager POST:urlString parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        //上传文件参数
        //UIImage *iamge = [UIImage imageNamed:@"123.png"];
        //NSData *data = UIImagePNGRepresentation(iamge);
        //这个就是参数
        [formData appendPartWithFileData:data name:@"file" fileName:fileName mimeType:@"image/jpg"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
        //打印下上传进度
        progress(@(1.0 *uploadProgress.completedUnitCount / uploadProgress.totalUnitCount));
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        //请求成功
        NSLog(@"上传文件成功：%@",responseObject);
        NSDictionary *dic = [responseObject[@"items"] firstObject];
        NSString *dataStr = [dic objectForKey:@"FileUrl"];
        success(dataStr);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        //请求失败
        NSLog(@"请求失败：%@",error);
        if (failure) {
            failure(error);
        }
    }];
    
}

- (RACSignal *)feedbackWithUserId:(NSString *)userId content:(NSString *)content {
    NSString *URLString = @"/pubapi.asmx/Feedback";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    if (userId) {
        [parameters setObject:userId forKey:@"UserId"];
    }
    if (content) {
        [parameters setObject:content forKey:@"Content"];
    }
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
}

- (RACSignal *)checkReviewStatus {
    NSString *URLString = @"/Api/v2/AppStore/IOSAuditVersion";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] forKey:@"version"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
}


- (RACSignal *)canCashOutIsAuthorizeRecordWithUserId:(NSString *)userId andYear:(int)year  andMonth:(int)month pageIndex:(int)page andSign:(NSString *)secretKey{
    NSString *URLString = @"Api/v1/Gongmao/WithdrawDepositRecord";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userId ?:@""                     forKey:@"userId"];
    [parameters setObject:@(year) ?: @""                   forKey:@"year"];
    [parameters setObject:@(month)  ?: @""                 forKey:@"month"];
    [parameters setObject:secretKey ?: @""                 forKey:@"sign"];
    [parameters setObject:@(1000)                          forKey:@"pageCount"];
    
    return [self XLPOST:URLString parameters:parameters resultClass:[BMHWithdrawalListModel class]];
}

-(RACSignal *)getIncomeDetailsListWithUserId:(NSString *)userId startTime:(NSString *)startTime endTime:(NSString *)endTime andSign:(NSString *)secretKey
{
    NSString *URLString = @"api/v1/Gongmao/GetUserIncomeByDate";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userId ?:@""                     forKey:@"userId"];
    [parameters setObject:startTime ?: @""                 forKey:@"startTime"];
    [parameters setObject:endTime  ?: @""                  forKey:@"endTime"];
    [parameters setObject:secretKey ?: @""                 forKey:@"sign"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    
}

-(RACSignal *)getAppconfigLis
{
    NSString *URLString = @"/api/V1/appconfig/getappconfig";
    [self.requestSerializer setValue:@"1"             forHTTPHeaderField:@"appId"];
    [self.requestSerializer setValue:QudaoName    forHTTPHeaderField:@"qudao"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self GET:URLString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
}

-(RACSignal *)getPublishDynamicVideoWihtUserID:(NSString *)userId titlles:(NSString *)Title content:(NSString *)Content picUrl:(NSString *)PicUrl screenType:(NSString *)ScreenType width:(NSString *)Width height:(NSString *)Height playCost:(NSString *)PlayCost andSign:(NSString *)secretKey
{
    NSString *URLString = @"/api/v1/AnchorIndex/PublishDynamicVideo";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userId      ?: @""                  forKey:@"userId"];
    [parameters setObject:Title       ?: @""                  forKey:@"Title"];
    [parameters setObject:Content     ?: @""                  forKey:@"Content"];
    [parameters setObject:PicUrl      ?: @""                  forKey:@"PicUrl"];
    [parameters setObject:ScreenType  ?: @""                  forKey:@"ScreenType"];
    [parameters setObject:Width       ?: @""                  forKey:@"Width"];
    [parameters setObject:Height      ?: @""                  forKey:@"Height"];
    [parameters setObject:PlayCost    ?: @""                  forKey:@"PlayCost"];
    [parameters setObject:secretKey   ?: @""                  forKey:@"sign"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    
}

-(RACSignal *)getVideoChatDiscountD:(NSString *)callID callUserID:(NSString *)callUserID Anchorid:(NSString *)anchorid
{
    NSString *URLString = @"/Api/v1/VideoCall/Charge";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:callID      ?: @""                  forKey:@"callId"];
    [parameters setObject:callUserID  ?: @""                  forKey:@"callUserId"];
    [parameters setObject:anchorid    ?: @""                  forKey:@"anchorid"];
    [parameters setObject:QudaoName                       forKey:@"qudao"];
    [parameters setObject:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]   forKey:@"version"];
    [parameters setObject:@"1"                                 forKey:@"appid"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    
}

-(RACSignal *)getVideoChatEndCallID:(NSString *)callID userId:(NSString *)userId anchorId:(NSString *)anchorId endType:(NSString *)endType
{
    NSString *URLString = @"/api/v2/VideoChat/EndCall";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:callID      ?: @""                  forKey:@"callId"];
    [parameters setObject:userId      ?: @""                  forKey:@"userId"];
    [parameters setObject:anchorId    ?: @""                  forKey:@"anchorId"];
    [parameters setObject:endType     ?: @""                  forKey:@"endType"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    
    
    
}

-(RACSignal *)getAnchorRewardUserId:(NSString *)userId
{
    NSString *URLString = @"/Api/v1/UserOrder/GetAnchorReward";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userId    ?: @""                  forKey:@"userId"];
    [parameters setObject:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]                  forKey:@"version"];
    [parameters setObject:@"1"                                forKey:@"appid"];
    [parameters setObject:QudaoName                       forKey:@"qudao"];
    return [self GET:URLString parameters:parameters resultClass:[XLCharmModel class]];
}

-(RACSignal *)GetUserConsumeRankUserId:(NSString *)userId
{
    NSString *URLString = @"/Api/v1/UserOrder/GetUserConsumeRank";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userId    ?: @""                  forKey:@"userId"];
    [parameters setObject:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]                        forKey:@"version"];
    [parameters setObject:@"1"                                      forKey:@"appid"];
    [parameters setObject:QudaoName                             forKey:@"qudao"];
    return [self GET:URLString parameters:parameters resultClass:[XLCharmModel class]];
}
- (RACSignal *)getMyLevelInforWithlevelNumber:(NSString *)levelNum lesvelType:(NSString *)type{//我的等级信息
    NSString *URLString = @"/api/v1/UserTask/GetUserLevelInfo";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:levelNum ?: @"" forKey:@"levelNo"];
    [parameters setObject:type ?: @"" forKey:@"levelType"];
    return [self GET:URLString parameters:parameters resultClass:[XLLevelInforModel class]];
}
-(RACSignal *)getSetStatusOfAnchorLiveChatAnchorld:(NSString *)anchorId IsLive:(NSString *)isLiveLanguageChat
{
    NSString *URLString = @"Api/v1/UserInfo/SetStatusOfAnchorLiveChat";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:anchorId    ?: @""                  forKey:@"anchorId"];
    [parameters setObject:isLiveLanguageChat ?:@""             forKey:@"isLiveLanguageChat"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask * task = [self GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
        
    }];
}

@end
